S210: User Management Module Modernization Plan

Documentation for Plans

S210: User Management Module Modernization Plan

Session: 210 Branch: session-210 Sub-session completed: 210.1 (spec + design) Date: 2026-03-12 Status: Spec complete, implementation pending


1. Session Mission

Modernize the modules/core-modules/user-management module to become a production-ready, portable core module that:

  1. Uses real backend-api endpoints instead of mock data
  2. Replaces NGXS state management with autoFlashState from @storage-system
  3. Incorporates the corrected L0-L4 user tier hierarchy established in Session 209
  4. Supports both immutable SystemRoles and custom space-level roles
  5. Works in both gspace1 AND dynamically generated platforms (portability requirement)

The broader context: this module is a core-module — it will be reused across every platform generated by the GoGrab platform builder. It must be architecturally clean, portable, and correctly enforce the user hierarchy.


2. Work Completed

2.1 Vitto Governance Hardening (Session 209, carried into 210)

Eight files modified to fix a foundational misalignment where developers were incorrectly placed at L0 instead of executives:

File Change
libs/libs-ui/auth-ui/src/lib/models/auth.types.ts Fixed L0-L4 tier comments; added executive to UserRole type
libs/libs-api/auth-core/src/lib/guards/roles.guard.ts Updated JSDoc to document full hierarchy including executive(90)
APIs/backend-vitto-api/src/app/auth/roles.guard.ts Replaced flat string-match guard with re-export of hierarchy-aware @libs-api/auth-core guard
APIs/backend-vitto-api/src/app/engine/vitto.controller.ts Added @Roles(SystemRoles.EXECUTIVE) to 6 unguarded endpoints (executive instructions + persona mutations)
APIs/backend-vitto-api/src/app/engine/vitto-config.service.ts Fixed role mapping: executive+developer=developer tier, admin=platform_builder tier
libs/libs-ai/vitto-core/src/lib/services/brain-context.service.ts Added isExecutive computed signal; updated isAdmin to include executive
libs/libs-ai/vitto-hub/src/lib/components/vitto-settings/vitto-settings.component.ts Fixed role-to-tier mapping; added isExecutive computed
libs/libs-space/theme-designer/src/lib/theme-dashboard/theme-dashboard.component.ts Added executive to isAdminOrDev check

2.2 Design Spec Written and Reviewed

Complete spec at: docs/superpowers/specs/2026-03-12-user-management-module-modernization-design.md

Key design decisions:

2.3 MCP Intelligence Captured

2.4 Documentation Created


3. Current System State

What Works

What Exists But Is Not Functional

What Is Missing


4. Critical Gaps

Gap 1: No Backend CRUD for L1/L2 Users

Why it matters: The user-management module cannot function without backend endpoints to create, update, delete, and manage users. The existing backend only has: (a) self-registration at /api/auth/register, (b) basic admin list at /api/admin/users, (c) platform user (L4) CRUD at /api/spaces/:spaceId/universes/:universeId/users.

Root cause: The backend was built incrementally — auth first, then platform users for generated platforms. Full admin user CRUD was never needed because there were only 2 founders + developers accessing the system directly.

What prevents correct behavior: Without these endpoints, the frontend module has no backend to talk to. The mock API masks this completely.

Gap 2: No Role Schema or Endpoints in Backend

Why it matters: Custom space-level roles (e.g., "Content Reviewer", "Billing Manager") require a Role schema in MongoDB and CRUD endpoints. SystemRoles are constants in code, but custom roles must be persisted.

Root cause: Roles were hardcoded as string arrays on the User document (roles: ['user']). No dedicated Role entity was ever created in backend-api.

Gap 3: Module Uses NGXS (Incompatible with Generated Platforms)

Why it matters: Generated platforms do NOT include NGXS (removed in S206). If the user-management module uses NGXS, it cannot be embedded in generated platforms.

Root cause: The module was built before the decision to remove NGXS from generated platforms.

Gap 4: Module Models Don't Reflect Corrected Tier Hierarchy

Why it matters: The module's user.model.ts defines SystemRoles as ADMIN > MANAGER > USER > VIEWER — missing EXECUTIVE entirely. Role hierarchy enforcement in UserRoleManagerComponent is based on the old 4-level hierarchy.

Root cause: Session 209 corrected the hierarchy in auth-core and Vitto, but the user-management module was not updated.

Gap 5: Dynamic CRUD Generation Strategy Undefined

Why it matters: The user-management module needs to work across dynamically generated platforms, each with their own backend. The strategy for how modules discover and connect to their backend hasn't been formalized beyond "configurable base URL".

Root cause: This is an architectural decision that hasn't been made yet. The user explicitly asked to discuss this as a follow-up.


5. Prioritized Recommendations

Tier 1 — High leverage / low effort

1.1 Write implementation plan using writing-plans skill

1.2 Implement models & types with L0-L4 hierarchy

1.3 Implement autoFlashState for UI state

Tier 2 — Medium effort / high impact

2.1 Implement API Service + Repository layers

2.2 Implement backend-api endpoint enhancements

2.3 Implement components (13 total)

Tier 3 — Large or transformative work

3.1 Implement routes with guards and permissions

3.2 Module manifest and integration

3.3 Follow-up: Dynamic CRUD generation for platforms


6. The One Highest-Leverage Next Step

Write the implementation plan using the writing-plans skill, then start with models + autoFlashState (Tier 1.1 → 1.2 → 1.3).

Why: The models are the foundation everything else depends on. Getting the types right (with the corrected L0-L4 hierarchy, both SystemRoles and RegistrationUserType, proper request/response contracts) prevents cascading type errors across all other layers. The autoFlashState migration is small but critical — it removes the NGXS dependency that blocks portability.

The backend endpoints (Tier 2.2) can be built in parallel by a separate agent if available, since they're independent of the frontend work.


7. Files / Systems to Inspect

Frontend Module (Primary Target)

modules/core-modules/user-management/src/lib/
├── models/                    # UPDATE: Add executive, align with auth.types.ts
├── services/                  # REPLACE: Wire to real backend, not mock
├── state/                     # REPLACE: NGXS → autoFlashState
├── components/                # UPDATE: 8 → 13, modernize patterns
├── data/repositories/         # UPDATE: Wire to real API services
├── actions/                   # KEEP: Public actions for cross-module use
├── events/                    # KEEP: Domain events
├── mocks/                     # KEEP: For dev/test, but not default
├── user-management.module.ts  # UPDATE: Module manifest
└── user-management.routes.ts  # UPDATE: Add role routes, fix guards

gmodules1 Reference (Source for Rebuild)

/Users/fguijarro/developer/repos-gspace/gmodules1/libs/modules/user-management/src/lib/

This has the 13-component structure, modern patterns, workflow state machine, and role management that gspace1's module lacks.

Backend API (Endpoints to Add)

APIs/backend-api/src/app/admin/admin-stats.controller.ts  # Existing, to extend
APIs/backend-api/src/app/admin/admin-stats.service.ts     # Existing service
APIs/backend-api/src/app/users/users.controller.ts        # DO NOT modify (has /me/* routes)
APIs/backend-api/src/app/users/users.service.ts           # Existing, may reuse methods
libs/libs-api/backend-core/src/lib/schemas/user.schema.ts # User schema, may need status field
libs/libs-api/backend-core/src/lib/schemas/               # Add role.schema.ts here

Auth & Types (Already Fixed in S209)

libs/libs-ui/auth-ui/src/lib/models/auth.types.ts         # UserRole now includes 'executive'
libs/libs-api/auth-core/src/lib/auth-core.constants.ts     # SystemRoles, ADMIN_ROLES
libs/libs-api/auth-core/src/lib/guards/roles.guard.ts      # Hierarchy-aware guard

Storage System (autoFlashState Reference)

libs/libs-foundational/storage-system/src/flash/helpers/auto-flash-state.ts  # Main API
libs/libs-foundational/storage-system/src/flash/index.ts                     # Exports
docs/english/GoGrab-Space/theme-system/flash-persistence-integration.md      # Usage examples
docs/english/GoGrab-Space/docs.libs/docs.libs-foundational/storage-system/   # Full docs

Key import: import { autoFlashState } from '@storage-system' Returns: AutoFlashSignal<T> — a WritableSignal<T> with .hydrated signal

Types to Carefully Review


8. Validation Checklist

Before Implementation

After Implementation

Edge Cases


9. MCP and Codebase Guidance

The next agent MUST use mcp-gograb-ai tools for context and decision logging:

Session Setup

preflight({ task: "User-management module implementation", sessionNumber: 210 })
session({ action: "set", sessionNumber: 210, subSessionNumber: 2 })

Before Major Decisions

find_similar({ query: "user management module CRUD" })
intelligence({ action: "recall", situation: "module modernization pattern" })
convention({ action: "get", category: "angular" })

After Implementation Steps

log_decision({ type: "implementation", question: "...", chosen: "...", reasoning: "...", confidence: 0.9, files: [...] })
outcome({ action: "report", decisionId: "...", wasSuccessful: true/false })

If Encountering Issues

intelligence({ action: "simulate", simulateAction: "...", context: "...", alternatives: [...] })
intelligence({ action: "calibrate", rawConfidence: 0.X, domain: "angular" })

Key Conventions Already Established


10. COPY/PASTE PROMPT FOR SESSION 210

You are continuing Session 210 (sub-session 2+) on branch `session-210`.

## Mission
Implement the user-management module modernization based on the approved spec at:
`docs/superpowers/specs/2026-03-12-user-management-module-modernization-design.md`

## Current State
- Branch: `session-210`
- Spec: Complete and reviewed (sub-session 210.1)
- Governance fixes: Complete (8 files updated in S209 — tier hierarchy, role guards, executive role)
- Implementation: NOT STARTED

## What Needs to Be Built (in order)

1. **Write implementation plan** — Use the `writing-plans` skill to convert the spec into a step-by-step build plan
2. **Models & types** — Update `modules/core-modules/user-management/src/lib/models/` with corrected L0-L4 hierarchy, both SystemRoles and RegistrationUserType, proper request/response contracts
3. **autoFlashState integration** — Replace NGXS state with `autoFlashState` from `@storage-system` for UI state (filters, pagination, viewMode, bulkSelection). Import: `import { autoFlashState } from '@storage-system'`
4. **API Service + Repository layers** — `UserApiService`, `RoleApiService` with configurable base URL. `UserRepository`, `RoleRepository` wrapping the API services.
5. **Backend-api enhancements** — New `AdminUsersController` at `/api/admin/users` with full CRUD + status + roles + bulk. New `Role` schema. Located at `APIs/backend-api/src/app/admin/`.
6. **Components (13 total)** — Base on gmodules1 versions at `/Users/fguijarro/developer/repos-gspace/gmodules1/libs/modules/user-management/src/lib/`. Modernize: standalone, OnPush, inject(), signals, autoFlashState, separate .ts/.html/.scss files.
7. **Routes with guards** — User routes + role routes with authGuard, permissionGuard, roleGuard composition.
8. **Module manifest** — `@ModuleDecorator` with lifecycle, navigation, public actions, embeddables.

## Critical Rules
- NEVER use NGXS — use `autoFlashState` from `@storage-system` for persistent UI state
- All components: standalone, OnPush, inject(), signals, separate files
- All async: RxJS Observables only — no Promises, no setTimeout
- API base URL must be injectable (not hardcoded) — for portability to generated platforms
- Role hierarchy: executive(90) > developer(80) > admin(60) > manager(40) > editor(20) > viewer(10)
- Two classification systems: `role` (UserRole — access control) vs `userType` (RegistrationUserType — hierarchy category)
- Backend endpoints at `/api/admin/users` (NOT `/api/users` — that path has existing `/me/*` routes)
- Use `@Roles(SystemRoles.ADMIN)` on all admin endpoints, with service-level check for executive-only role assignments
- Follow `docs/english/Prompts/global-engineering-standard.md` for code quality

## Key Files to Read First
1. `docs/superpowers/specs/2026-03-12-user-management-module-modernization-design.md` — THE SPEC
2. `modules/core-modules/user-management/src/` — Current gspace1 module (to be replaced)
3. `/Users/fguijarro/developer/repos-gspace/gmodules1/libs/modules/user-management/src/` — gmodules1 reference (source for rebuild)
4. `libs/libs-ui/auth-ui/src/lib/models/auth.types.ts` — UserRole, RegistrationUserType
5. `libs/libs-api/auth-core/src/lib/auth-core.constants.ts` — SystemRoles
6. `libs/libs-foundational/storage-system/src/flash/helpers/auto-flash-state.ts` — autoFlashState API
7. `docs/english/GoGrab-Space/theme-system/flash-persistence-integration.md` — autoFlashState usage examples

## MCP Setup
Run these at session start:
- preflight({ task: "User-management module implementation", sessionNumber: 210 })
- session({ action: "set", sessionNumber: 210, subSessionNumber: 2 })
- convention({ action: "get", category: "angular" })

## Follow-up Discussion (After Module is Complete)
The user wants to discuss dynamic CRUD generation strategy for platforms — how modules discover and connect to their backend APIs in generated platforms. Flag this for discussion once the user-management module is working.

## Git Protocol
- Commits: `[S210.{sub}] type: description`
- Staging: `git add <specific-files>` — NEVER `git add .`
- Sub-session: increment from last known (start at 210.2)